package main

import (
	"fmt"
	"time"
)

func writeDate(intChan chan int) {
	for i := 0; i < 50; i++ {
		time.Sleep(100 * time.Millisecond)
		intChan <- i
	}
	close(intChan)
}
func readData(intChan chan int, exitChan chan bool) {
	for {
		v, ok := <-intChan
		if !ok {
			break
		}
		fmt.Println(v)
	}
	exitChan <- true
	close(exitChan)

}
func main() {

	intChan := make(chan int, 50)
	exitChan := make(chan bool, 1)
	go writeDate(intChan)
	go readData(intChan, exitChan)
	<-exitChan
	fmt.Println("main end")
}
